from django.db import models
from user.models import Manager, Student, Clazz


class CheckInTask(models.Model):
    name = models.CharField(max_length=30, verbose_name='名称', null=False)
    start_time = models.DateTimeField(null=False, verbose_name='开始时间')
    end_time = models.DateTimeField(null=False, verbose_name='结束时间')
    manager = models.ForeignKey(Manager, on_delete=models.DO_NOTHING, verbose_name='发布者')
    publish_date = models.DateTimeField(auto_now=True, verbose_name='发布时间')

    class Meta:
        verbose_name = '签到任务'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


class StudentCheckIn(models.Model):
    student = models.ForeignKey(Student, on_delete=models.DO_NOTHING, verbose_name='学生')
    task = models.ForeignKey(CheckInTask, on_delete=models.DO_NOTHING, verbose_name='签到任务')
    date = models.DateTimeField(auto_now=True, verbose_name='签到时间')
    file_path = models.CharField(max_length=200, verbose_name='文件地址')

    class Meta:
        verbose_name = '学生签到'
        verbose_name_plural = verbose_name
        unique_together = ('student', 'task')

    def __str__(self):
        return str(self.student) + ' - ' + str(self.date.date())

